package com.coda.mapper;

import com.coda.adminVo.attr.AttrValueVo;
import com.coda.adminVo.graph.GraphVo;
import com.coda.adminVo.room.RoomItemVo;
import com.coda.adminVo.room.RoomQueryVo;
import com.coda.annotation.AutoFill;
import com.coda.entity.*;
import com.coda.enumeration.OperationType;
import com.github.pagehelper.Page;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface RoomMapper {
    /**
     * 根据公寓id查询关联的房间数量
     * @param id
     * @return
     */
    @Select("select count(*) from room_info where  apartment_id = #{id}")
    Integer getCount(Long id);

    /**
     * 根据条件分页查询房间列表
     * @param roomQueryVo
     * @return
     */
    Page<RoomItemVo> getPageList(RoomQueryVo roomQueryVo);

    /**
     * 获取房间信息
     * @param id
     * @return
     */
    @Select("select * from room_info where id = #{id}")
    RoomInfo getRoom(Long id);

    /**
     * 删除房间信息
     * @param id
     */
    @Delete("delete from room_info where id =#{id}")
    void delete(Long id);

    /**
     * 删除对应的房间详细信息
     * @param id
     */
    @Delete("delete from room_lease_term where room_id = #{id}")
    void deleteRoomLeaseTerm(Long id);

    /**
     * 删除房间对应的支付类型
     * @param id
     */
    @Delete("delete from room_payment_type where room_id = #{id}")
    void deleteRoomPaymentType(Long id);

    /**
     * 删除房间对应的属性值
     * @param id
     */
    @Delete("delete from room_attr_value where room_id = #{id}")
    void deleteRoomAttrValue(Long id);

    /**
     * 删除房间对应的标签
     * @param id
     */
    @Delete("delete from room_label where room_id = #{id}")
    void deleteRoomLabel(Long id);

    /**
     * 删除房间对应的配套
     * @param id
     */
    @Delete("delete from room_facility where room_id = #{id}")
    void deleteRoomFacility(Long id);

    /**
     * 删除房间对应的图片
     * @param id
     */
    @Delete("delete from graph_info where item_type = 2 and item_id = #{id}")
    void deleteGraph(Long id);

    /**
     * 添加公寓信息
     * @param roomInfo
     */
    @AutoFill(OperationType.INSERT)
    void insertRoom(RoomInfo roomInfo);


    /**
     * 添加属性信息
     * @param roomAttrValueList
     */
    @AutoFill(OperationType.INSERT)
    void insertAttrValue(@Param("roomAttrValueList") List<RoomAttrValue> roomAttrValueList);

    /**
     * 添加配套信息
     * @param roomFacilities
     */
    @AutoFill(OperationType.INSERT)
    void insertFacility(@Param("roomFacilities") List<RoomFacility> roomFacilities);

    /**
     * 添加支付方式信息
     * @param roomPaymentTypesList
     */
    @AutoFill(OperationType.INSERT)
    void insertPaymentType(@Param("roomPaymentTypesList") List<RoomPaymentType> roomPaymentTypesList);

    /**
     * 添加可选租期
     * @param roomLeaseTerms
     */
    @AutoFill(OperationType.INSERT)
    void insertLeaseTerm(@Param("roomLeaseTerms") List<RoomLeaseTerm> roomLeaseTerms);

    /**
     * 添加标签信息
     * @param roomLabelList
     */
    @AutoFill(OperationType.INSERT)
    void insertLabel(@Param("roomLabelList") List<RoomLabel> roomLabelList);

    /**
     * 更新房间信息
     * @param roomInfo
     */
    void updateRoom(RoomInfo roomInfo);

    /**
     * 根据房间id获取房间信息
     * @param id
     * @return
     */
    @Select("select name,url from graph_info where item_id = #{id} and item_type = 2")
    List<GraphVo> getGraph(Long id);

    /**
     * 根据房间id获取属性值
     * @param id
     * @return
     */
    List<AttrValueVo> getAttrValue(Long id);

    /**
     * 根据房间id获取配套信息
     * @param id
     * @return
     */
    List<FacilityInfo> getFacility(Long id);

    /**
     * 根据房间id获取标签信息
     * @param id
     * @return
     */
    List<LabelInfo> getLabelInfo(Long id);

    /**
     * 根据房间id查询支付类型
     * @param id
     * @return
     */
    List<PaymentType> getPaymentType(Long id);

    /**
     * 根据房间id查询租期信息
     * @param id
     * @return
     */
    List<LeaseTerm> getLeaseTermList(Long id);

    /**
     * 根据公寓id查询房间信息列表
     * @param id
     * @return
     */
    @Select("select * from room_info where apartment_id = #{id}")
    List<RoomInfo> getRoomInfo(Long id);

    /**
     * 根据公寓id获取房间总数
     * @param id
     * @return
     */
    @Select("select count(*) from room_info where apartment_id = #{id} and is_release = 1")
    Long getRoomSumCount(Long id);

    /**
     * 根据公寓id获取空闲房间数
     */
    Long getFreeRoomCount();
}
